/*
 * Copyright (c) 2012 Banaanvraag
 * MIT Licence
 */
package banaanvraag.tools.arrays;

/**
 * Tools for checking arrays.
 * Currently not more than index checks.
 * @author Luc
 */
public class ArrayTools {
    
    /**
     * Checks whether an array contains a key or not.
     * @param array The array to check
     * @param index The index to check
     * @return True if <code>index &gt; 0</code> and <code>index &lt; array.length()</code>, otherwise false
     */
    public static boolean hasIndex(Object[] array, int index) {
        if(index >= 0 && index < array.length) {
            return true;
        }
        return false;
    }
    
    /**
     * Checks if a 2-dimensional array contains these keys
     * @param array The 2-dimensional array to check
     * @param a The key of the first array
     * @param b The key of the second array
     * @return True if both are valid keys for the arrays, otherwise false
     * @see hasIndex(Object[] array, int index)
     */
    public static boolean hasIndex(Object[][] array, int a, int b) {
        if((a >= 0 && b >= 0) 
                && a < array.length 
                && b < array[0].length) {
            return true;
        }
        return false;
    }
    
    /**
     * Checks if a 3-dimensional array contains these keys
     * @param array The 3-dimensional array to check
     * @param a The key of the first array
     * @param b The key of the second array
     * @param c The key of the third array
     * @return True if these are valid keys for the arrays, otherwise false
     * @see hasIndex(Object[], int index)
     */
    public static boolean hasIndex(Object[][][] array, int a, int b, int c) {
        if((a >= 0 && b >= 0 && c >= 0)
                && a < array.length
                && b < array[0].length
                && c < array[0][0].length) {
            return true;
        }
        return false;
    }
}
